package
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.utils.getDefinitionByName;
	
	import leaf.science.ui.preloader.Preloader;

	[SWF(frameRate="60", backgroundColor="#ECECEC", width="1024", height="680")]
	public class LeafScienceLoader extends MovieClip
	{
		public var preloader:Preloader;
		
		public function LeafScienceLoader()
		{
			stop();
			stage.scaleMode = 'noScale';
			stage.align = 'TL';
			stage.showDefaultContextMenu = false;
			stage.addEventListener(Event.RESIZE, onResize);
			
			preloader = new Preloader();
			preloader.alpha = 0.5;
			addChild(preloader);
			
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			
			onResize();
		}
		
		private function onResize (evt:Event = null):void
		{
			preloader.x = stage.stageWidth / 2;
			preloader.y = stage.stageHeight / 2;
		}
		
		private function onEnterFrame(evt:Event):void
		{
			if (framesLoaded == totalFrames){
				onLoadComplete();
			}
		}
		
		private function onLoadComplete():void
		{
			preloader.stop();
			removeChild(preloader);
			removeEventListener(Event.ENTER_FRAME, onEnterFrame);
			removeEventListener(Event.RESIZE, onResize);
			nextFrame();
			
			var Main:Class = Class(getDefinitionByName("LeafScience"));
			var app:Object = new Main();
			addChild(app as DisplayObject);
		}
		
	}
}